// const mySet = new Set([1,2,3])
// console.log(mySet)


// 手写一个Set

class Set {
  constructor () {
    this.items = {}
    this.size = 0
  }
  has (ele) {
    return ele in this.items
  }
  add (ele) {
    if (!this.has(ele)) {
      this.items[ele] = ele
      this.size++
    }
    return this
  }
  clear(){
    this.items = {}
    this.size = 0
  }
  delete(ele) {
    if (this.has(ele)) {
      delete this.items[ele]
      this.size--
    }
    return this
  }
  values () {
    let result = []
    Object.keys(this.items).forEach(key=>{
      result.push(key)
    })
    return result
  }
}

function keyToString(val) {
  if (val === null) {
    return 'NULL'
  } else if (typeof val === 'undefined') {
    return 'UNDEFINED'
  } else if (typeof val === 'object') {
    return JSON.stringify(val)
  }
  return val.toString()
}
// 手写一个Map

class Map {
  constructor(){
    this.items = {}
    this.size = 0
  }
  set(key, val) {
    if (!this.has(keyToString(key))) {
      this.items[keyToString(key)] = val
      this.size++
    } else {
      this.items[keyToString(key)] = val
    }
  }
  get (key){
    return this.items[keyToString(key)]
  }
  has(key){
    return keyToString(key) in this.items
  }
  delete (key) {
    if (this.has(key)) {
      delete this.items[keyToString(key)]
      this.size--
    }
  }
  clear(){
    this.items = {}
    this.size = 0
  }

}


// const myMap = new Map()
// myMap.set('name','lucy')
// myMap.set('age',23)

class Parent{}
class Child extends Parent{
  constructor(){
    super()
  }
}
const child1 = new Child()

function intanceof(child, parent) {
  let childProto = child.__proto__
  while(true) {
    if (childProto === null) return false
    if (childProto === parent.prototype) return true
    childProto = childProto.__proto__
  }
}

console.log(intanceof(child1,Parent))
console.log(intanceof(child1,Child))
console.log(intanceof([],Object))

function getCamelCase(str) {
  const arr = str.split('_')
  return arr.map((item,index)=>{
    if (index === 0) {
      return item
    } else {
      return item.charAt(0).toUpperCase()+item.slice(1)
    }
  }).join('')
}
const str = 'abc_name_age'
const str1 = getCamelCase(str)
console.log(str1)